<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    {
        function getIndex(arr){
            let index = 0
            arr.reduce((acc,cur)=>{
                if (acc.length > 0){
                    acc[1]++
                    if (cur > 0){
                        if (acc[0]){
                            if (acc[0] > cur){
                                index = acc[1]
                            }
                        } else {
                            acc[0] = cur
                            index = acc[1]
                        }
                    }
                } else {
                    acc = [,0]
                    if (cur > 0){
                        acc[0] = cur
                    } else {
                        acc[0] = null
                    }
                    index = acc[1]
                }
                return acc
            },[])
            return index
        }

        const arr = [3,321,31,23,5,465,324,534,22,4,1,-2,5,-12,-42,-55,0]
        console.log(getIndex(arr))
    }
    {
        function getIndex(arr){
            let min = Infinity
            let index = -1
            arr.forEach((item,i)=>{
                if (item > 0 && item < min){
                    min = item
                    index = i
                }
            })
            return index
        }
        const arr = [3,321,31,23,5,465,324,534,22,4,1,-2,5,-12,-42,-55,0]
        console.log(getIndex(arr))
    }
</script>
</html>